package bigdata.api.echart.datapush;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import bigdata.task.DataPushTask;
import framework.util.date.DateStyle;
import framework.util.date.DateUtil;

@Controller
@RequestMapping("/datapushBatch")
public class BatchUpdateController {
	/*@Autowired
	DataPushTask dataPushTask;

	@RequestMapping(params = { "method=update" })
	@ResponseBody()
	public String update() {
		Date startDate = DateUtil.StringToDate("2016-01-01",
				DateStyle.YYYY_MM_DD);
		// 从2016-01开始
		List<String> dateStrs1 = getYyyyMM(startDate);

		for (String yyyyMM : dateStrs1) {
			dataPushTask.dataPushDistributionTask(yyyyMM);
		}

		// 从2016-01-01
		List<String> dateStrs2 = getYyyyMMdd(startDate);
		for (String yyyyMMdd : dateStrs2) {
			dataPushTask.dailyTouristTotal(yyyyMMdd);
		}
		dataPushTask.tourTraceDistributionTask();
		return "成功";
	}

	@RequestMapping(params = { "method=test" })
	@ResponseBody()
	public void test(String time) {
		dataPushTask.dailyTouristTotal(time);
	}

	private List<String> getYyyyMM(Date startDate) {
		List<String> list = new ArrayList<String>();

		String now = DateUtil.DateToString(new Date(), DateStyle.YYYYMM);
		boolean flag = true;
		int i = 0;
		while (flag) {
			Date computeDate = DateUtil.addMonth(startDate, i);
			String dateStr = DateUtil.DateToString(computeDate,
					DateStyle.YYYYMM);

			if (now.equals(dateStr))
				flag = false;
			++i;
			list.add(dateStr);
		}

		return list;

	}

	private List<String> getYyyyMMdd(Date startDate) {
		List<String> list = new ArrayList<String>();

		String now = DateUtil.DateToString(new Date(), DateStyle.YYYYMMDD);
		boolean flag = true;
		int i = 0;
		while (flag) {
			Date computeDate = DateUtil.addDay(startDate, i);
			String dateStr = DateUtil.DateToString(computeDate,
					DateStyle.YYYYMMDD);

			if (now.equals(dateStr))
				flag = false;
			++i;
			list.add(dateStr);
		}

		return list;
	}*/

}
